﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ThomasGIS.Geometries
{
    public class SingleLine : GeometryBase, ISingleLine
    {
        public Point StartPoint { get; set; }
        public Point EndPoint { get; set; }

        public SingleLine(double sx, double sy, double ex, double ey)
        {
            StartPoint = new Point(sx, sy);
            EndPoint = new Point(ex, ey);
        }

        public SingleLine(IPoint startPoint, IPoint endPoint)
        {
            StartPoint = new Point(startPoint.GetX(), startPoint.GetY());
            EndPoint = new Point(endPoint.GetX(), endPoint.GetY());
        }

        public string ExportToWkt()
        {
            StringBuilder wktBuilder = new StringBuilder();
            wktBuilder.Append("LINESTRING (");
            wktBuilder.Append(StartPoint.X);
            wktBuilder.Append(" ");
            wktBuilder.Append(StartPoint.Y);
            wktBuilder.Append(",");
            wktBuilder.Append(EndPoint.X);
            wktBuilder.Append(" ");
            wktBuilder.Append(EndPoint.Y);
            wktBuilder.Append(")");
            return wktBuilder.ToString();
        }

        public IPoint GetStartPoint()
        {
            return this.StartPoint;
        }

        public IPoint GetEndPoint()
        {
            return this.EndPoint;
        }

        public bool SetStartX(double x)
        {
            this.StartPoint.SetX(x);
            return true;
        }

        public bool SetStartY(double y)
        {
            this.StartPoint.SetY(y);
            return true;
        }

        public bool SetEndX(double x)
        {
            this.EndPoint.SetX(x);
            return true;
        }

        public bool SetEndY(double y)
        {
            this.EndPoint.SetY(y);
            return true;
        }
    }
}
